package ink.carnation.imtalk.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author: flbu920
 * @date 2020/9/28
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ThreadPoolTaskExecutor createThreadPoolTaskExecutor() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        //核心线程数4
        threadPoolTaskExecutor.setCorePoolSize(4);
        //非核心线程数100
        threadPoolTaskExecutor.setMaxPoolSize(100);
        //任务队列容量为100
        threadPoolTaskExecutor.setQueueCapacity(100);
        //设置非核心线程过期时间为2分钟
        threadPoolTaskExecutor.setKeepAliveSeconds(120);
        return threadPoolTaskExecutor;
    }
}
